package org.example.quartz.controller;


import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.example.quartz.QuartzJobService;
import org.example.quartz.job.JobException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/quartz")
@Slf4j
@Api(tags = "quaetz定时任务")
public class QuartzJobController {
    @Autowired
    QuartzJobService quartzJobService;
    @PostMapping("/addjob")
    public void  addjob(@RequestParam("core") String core,@RequestParam("key") String key){
        try {
            quartzJobService.addjob(core,key);
        } catch (JobException e) {
            throw new RuntimeException(e);
        }
    }
    @PutMapping("/midifyjob")
    public void modifyJob(@RequestParam("core") String core,@RequestParam("key") String key){
        // 0/2 * * * * ?  每两秒一次
        quartzJobService.midify(core,key);
    }

    @DeleteMapping("deletejob")
    public void deletejob(@RequestParam("key") String key){
        quartzJobService.deleteJob(key);
    }


}
